package com.kangye.exam.controller;

import com.kangye.exam.service.intellectTestService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("intellectTest")
public class IntellectTestController {

    @Resource
    private intellectTestService intellectTestService;


    @RequestMapping("creatTest")
    public Object creatTest(Integer subjectId,Integer simple,Integer multip,Integer judge,Integer difficulty,Integer gradeId){
        if(simple==0&&multip==0&&judge==0&&subjectId==0){
            simple = 20;
            multip = 20;
            judge = 20;
            subjectId = 1;
        }
        Map<String,Object> map = new HashMap<>();
        map = intellectTestService.creatTest(subjectId,simple,multip,judge,difficulty,gradeId);
        if(map.size()>0){
            map.put("code",0);
        }else{
            map.put("code",-1);
        }
        return map;
    }

    @RequestMapping("wrongItem")
    public Object wrongItem(Integer stuId,String error,String errorId){
        Map<String,Object> map = new HashMap();
        if(stuId!=null){
            if(intellectTestService.wrongItem(stuId,error,errorId)){
                map.put("code",0);
            }else{
                map.put("code",-1);
            }
        }else{
            map.put("code",-2);
        }
        return map;
    }



}
